﻿namespace WebOptimizer.UI.Entities
{
	[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
	public sealed partial class Task : global::WebOptimizer.UI.Entities.Core.BusinessBase, global::WebOptimizer.Data.ITask
	{
		#region Business Members

		#region IsEnabled

		private bool _IsEnabled = false;
		partial void OnBeforeIsEnabledPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
		partial void OnBeforeIsEnabledPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
		partial void OnAfterIsEnabledPropertyChanged();
		public bool IsEnabled
		{
			get
			{
				Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_IsEnabled);
				OnBeforeIsEnabledPropertyGet(eventData);
				return eventData.Value;
			}
			set
			{
				Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IsEnabled);
				OnBeforeIsEnabledPropertyChanged(eventData);
				if (!eventData.Cancel)
				{
					LoadInstanceField("IsEnabled", eventData.Value, true, true, true);
					OnAfterIsEnabledPropertyChanged();
				}
			}
		}

		#endregion
		#region Path

		private string _Path = string.Empty;
		partial void OnBeforePathPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
		partial void OnBeforePathPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
		partial void OnAfterPathPropertyChanged();
		public string Path
		{
			get
			{
				Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_Path);
				OnBeforePathPropertyGet(eventData);
				return eventData.Value;
			}
			set
			{
				value = Sidvall.Business.ValidationManager.GetValidString(value, false, null);
				Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Path);
				OnBeforePathPropertyChanged(eventData);
				if (!eventData.Cancel)
				{
					LoadInstanceField("Path", eventData.Value, true, true, true);
					OnAfterPathPropertyChanged();
				}
			}
		}

		#endregion
		#region TaskId

		private System.Nullable<int> _TaskId = null;
		partial void OnBeforeTaskIdPropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<int>> eventData);
		partial void OnBeforeTaskIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
		partial void OnAfterTaskIdPropertyChanged();
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
		public System.Nullable<int> TaskId
		{
			get
			{
				Sidvall.Business.PropertyEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<int>>(_TaskId);
				OnBeforeTaskIdPropertyGet(eventData);
				return eventData.Value;
			}
			internal set
			{
				Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _TaskId);
				OnBeforeTaskIdPropertyChanged(eventData);
				if (!eventData.Cancel)
				{
					LoadInstanceField("TaskId", eventData.Value, true, true, true);
					OnAfterTaskIdPropertyChanged();
				}
			}
		}

		#endregion
		#region TaskTypeId

		private global::WebOptimizer.Data.TaskType _TaskTypeId = global::WebOptimizer.Data.TaskType.CompressJavaScript;
		partial void OnBeforeTaskTypeIdPropertyGet(Sidvall.Business.PropertyEventData<global::WebOptimizer.Data.TaskType> eventData);
		partial void OnBeforeTaskTypeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<global::WebOptimizer.Data.TaskType> eventData);
		partial void OnAfterTaskTypeIdPropertyChanged();
		public global::WebOptimizer.Data.TaskType TaskTypeId
		{
			get
			{
				Sidvall.Business.PropertyEventData<global::WebOptimizer.Data.TaskType> eventData = new Sidvall.Business.PropertyEventData<global::WebOptimizer.Data.TaskType>(_TaskTypeId);
				OnBeforeTaskTypeIdPropertyGet(eventData);
				return eventData.Value;
			}
			set
			{
				Sidvall.Business.PropertyChangeEventData<global::WebOptimizer.Data.TaskType> eventData = new Sidvall.Business.PropertyChangeEventData<global::WebOptimizer.Data.TaskType>(value, _TaskTypeId);
				OnBeforeTaskTypeIdPropertyChanged(eventData);
				if (!eventData.Cancel)
				{
					LoadInstanceField("TaskTypeId", eventData.Value, true, true, true);
					OnAfterTaskTypeIdPropertyChanged();
				}
			}
		}

		#endregion
		#region Sources

		private SourceCollection _Sources;
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
		public SourceCollection Sources
		{
			get
			{
				return _Sources;
			}
			internal set
			{
				LoadInstanceField("Sources", value, true, false, false);
			}
		}

		#endregion
		#region IsBusy

		public override bool IsBusy
		{
			get
			{
				return global::WebOptimizer.UI.SystemContext.Current.EntityFacade.TaskManager.IsBusy(this);
			}
		}

		#endregion
		#region IsDirty

		public override bool IsDirty
		{
			get
			{
				return global::WebOptimizer.UI.SystemContext.Current.EntityFacade.TaskManager.IsDirty(this);
			}
		}

		#endregion

		#region LoadSources

		public void LoadSources(SourceCollection value)
		{
			LoadInstanceField("Sources", value, true, true, false);
		}

		#endregion
		#region LoadInstanceField

		public void LoadInstanceField(global::WebOptimizer.Data.Fields.TaskField fieldId, object value, bool cascade, bool raisePropertyChanged, bool updateState)
		{
			global::WebOptimizer.UI.SystemContext.Current.EntityFacade.TaskManager.LoadInstanceField(this, fieldId, value, cascade, raisePropertyChanged, updateState);
		}
		public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
		{
			global::WebOptimizer.UI.SystemContext.Current.EntityFacade.TaskManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
		}

		#endregion
		#region AcceptChanges

		public void AcceptChanges()
		{
			global::WebOptimizer.UI.SystemContext.Current.EntityFacade.TaskManager.AcceptChanges(this);
		}

		#endregion
		#region Copy

		public Task Copy()
		{
			return global::WebOptimizer.UI.SystemContext.Current.EntityFacade.TaskManager.Copy(this) as Task;
		}
		public Task Copy(Sidvall.Data.CopySettings settings)
		{
			return global::WebOptimizer.UI.SystemContext.Current.EntityFacade.TaskManager.Copy(this, settings) as Task;
		}

		#endregion
		#region Import

		public void Import(global::WebOptimizer.Data.ITask item)
		{
			global::WebOptimizer.UI.SystemContext.Current.EntityFacade.TaskManager.Import(this, item);
		}
		public void Import(global::WebOptimizer.Data.ITask item, Sidvall.Data.CopySettings settings)
		{
			global::WebOptimizer.UI.SystemContext.Current.EntityFacade.TaskManager.Import(this, item, settings);
		}

		#endregion
		#region Validate

		public Sidvall.Data.BrokenRuleCollection Validate()
		{
			return global::WebOptimizer.UI.SystemContext.Current.EntityFacade.TaskManager.Validate(this);
		}
		public Sidvall.Data.BrokenRuleCollection Validate(Sidvall.Data.ValidationSettings settings)
		{
			return global::WebOptimizer.UI.SystemContext.Current.EntityFacade.TaskManager.Validate(this, settings);
		}

		#endregion
		
		#region ITask Members

		bool global::WebOptimizer.Data.ITask.IsEnabled
		{
			get
			{
				return this._IsEnabled;
			}
			set
			{
				this._IsEnabled = value;
			}
		}
		string global::WebOptimizer.Data.ITask.Path
		{
			get
			{
				return this._Path;
			}
			set
			{
				this._Path = value;
			}
		}
		System.Nullable<int> global::WebOptimizer.Data.ITask.TaskId
		{
			get
			{
				return this._TaskId;
			}
			set
			{
				this._TaskId = value;
			}
		}
		global::WebOptimizer.Data.TaskType global::WebOptimizer.Data.ITask.TaskTypeId
		{
			get
			{
				return this._TaskTypeId;
			}
			set
			{
				this._TaskTypeId = value;
			}
		}
		System.Collections.Generic.IEnumerable<global::WebOptimizer.Data.ISource> global::WebOptimizer.Data.ITask.Sources
		{
			get
			{
				return this._Sources;
			}
			set
			{
				UpdateChildProperty(this._Sources, value);
				this._Sources = value as SourceCollection;
			}
		}

		#endregion

		#endregion
		#region Constructors

		public Task()
		{
		}

		public Task(Sidvall.Data.DataRowState? dataRowState)
			: base(dataRowState)
		{
		}

		#endregion
	}
}